package com.yxd.connector.http;

import com.yxd.bootstrap.Constants;
import com.yxd.logging.SysLogger;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by Administrator on 2016/6/16.
 */
public class HttpConnector implements Runnable {

    private String scheme = "http";

    private boolean isStop = false;

    public String getScheme() {
        return scheme;
    }

    @Override
    public void run() {
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(Constants.PORT);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
        SysLogger.info("server is working at port:" + Constants.PORT);
        while (!isStop) {
            Socket socket = null;
            try {
                socket = serverSocket.accept();
            } catch (IOException ex) {
                ex.printStackTrace();
                continue;
            }
            HttpProcessor processor = new HttpProcessor(this, socket);
            processor.process();
        }
    }

    public void start() {
        Thread thread = new Thread(this);
        thread.start();
    }

}
